package com.fivec.javaproject.service;

import com.alibaba.fastjson.JSONObject;
import com.fivec.javaproject.Constants;
import com.fivec.javaproject.bean.AddressCommon;
import com.fivec.javaproject.bean.Address;
import com.fivec.javaproject.net.HttpUtils;

import java.net.URLEncoder;

/**
 * @author wangyizhu
 * @version "1.8.0_131"
 * @email 2641956765@qq.com
 * @desc:
 * @Time 2021/12/10 13:08
 */
public class AddressService {
    /**
     * 该方法用于获取手机号码归属地，并将数据返回
     *
     * @param number
     * @return Address
     */
    public Address getAddressMessage(String number) {
        number = URLEncoder.encode(number);
        String url = Constants.ADDRESS_URL
                + "?phone=" + number +
                "&key=" + Constants.ADDRESS_KEY;
        String result = HttpUtils.get(url);
        //  System.out.println(result);
        //json解析
        AddressCommon addressCommon = JSONObject.parseObject(result, AddressCommon.class);
        //System.out.println(videoCommon.result.size());
        return addressCommon.result;
    }
}
